﻿(function ($) {
    $.Cushajs = {
        initFangshaKind: function (CustomerID) {
            var _optionhtml = "";
            $("#cushakindlist").empty();
            $.ajax({
                url: "../MFG/MFGCusha.ashx",
                data: {
                    Action: "initFangshaKind",
                    CustomerID: CustomerID
                },
                async: true,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    if (data.length > 0) {
                        //_optionhtml += "<option value=''>请选择</option>";
                        for (i in data) {
                            _optionhtml += "<option value=\"" + data[i].FangShaKind.trim() + "\" >" + data[i].FangShaKind.trim() + "</option>";
                        }
                        //_optionhtml = "<option value='32#'>32#</option><option value='40#'>40#</option>"
                        console.log(_optionhtml)
                        $("#cushakindlist").html(_optionhtml);
                        //if (FangshaKind != "") {
                        //    $("#cushakindlist option[value="+FangshaKind+"]").prop("selected", 'selected');
                        //}
                        //$("#cushakindlist1").append(_optionhtml);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        inittotalFangshaKind: function (CustomerID, FangshaKind) {
            var _optionhtml = "";
            $("#cushakindlist").empty();
            $.ajax({
                url: "../MFG/MFGCusha.ashx",
                data: {
                    Action: "inittotalFangshaKind",
                    CustomerID: CustomerID
                },
                async: true,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    if (data.length > 0) {
                        //_optionhtml += "<option value=''>请选择</option>";
                        for (i in data) {
                            _optionhtml += "<option value=\"" + data[i].FangShaKind.trim() + "\" >" + data[i].FangShaKind.trim() + "</option>";
                        }
                        //_optionhtml = "<option value='32#'>32#</option><option value='40#'>40#</option>"
                        console.log(_optionhtml)
                        $("#cushakindlist").html(_optionhtml);
                        if (FangshaKind != "") {
                            $("#cushakindlist option[value=" + FangshaKind + "]").prop("selected", 'selected');
                        }
                        //$("#cushakindlist1").append(_optionhtml);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },
        getEquNolistByCustomerID: function (CustomerID, Type) {

            $("#equnolist").empty();
            $("#guzhangtongjiTaihaolist").empty();

            var _optionhtml = "";
            $.ajax({
                url: "../MFG/MFGCusha.ashx",
                data: {
                    Action: "getEquNolistByCustomerID",
                    CustomerID: CustomerID
                },
                async: true,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    if (data.length > 0) {
                        _optionhtml += "<option value=''>请选择</option>";
                        for (i in data) {
                            _optionhtml += "<option value=\"" + data[i].EquNo + "\" >" + data[i].TaiHao.trim() + "</option>";
                        }
                        if (Type == 1) {
                            $("#equnolist").html(_optionhtml);
                            $("#equnolist option:first").prop("selected", 'selected');
                            $("#equnolist1").html(_optionhtml);
                            $("#equnolist1 option:first").prop("selected", 'selected');
                            $.Cushajs.initdantaijianshitable($("#equnolist").find("option:selected").val(), $("#equnolist").find("option:selected").text(), $("#time").text());

                        }
                        else if (Type == 2) {
                            $("#equnolist1").html(_optionhtml);

                        }
                        else if (Type == 3) {

                            $("#taihaolist").html(_optionhtml);
                            var TiaHao = $("#taihaolist").find("option:selected").text();
                            var BanCi = $("#banciselect").find("option:selected").val();

                            var kaitingcheselect = $("#kaitingcheselect").val();
                            var Kaiting_StartTime = $("#Kaiting_StartTime").val();
                            var Kaiting_EndTime = $("#Kaiting_EndTime").val();

                            $.Cushajs.initKaitingcheInfo(CustomerID, TiaHao, kaitingcheselect, BanCi, Kaiting_StartTime, Kaiting_EndTime);
                        }
                        else if (Type == 4) {

                            $("#guzhangtongjiTaihaolist").html(_optionhtml);
                        }
                    }
                    else {
                        if (Type == 1) {
                            $("#equnolist").html("");
                        }
                        else if (Type == 2) {
                            $("#equnolist1").html("");
                        }
                        else if (Type == 3) {
                            $("#equnolist2").html("");
                        }
                        dialogMsg("未找到数据", 0);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        // 根据ID获取班次列表
        getBanciByCustomerID: function (CustomerID) {

            $("#banciselect").empty();
            var _optionhtml = "";
            $.ajax({
                url: "../MFG/MFGCusha.ashx",
                data: {
                    Action: "getBanciByCustomerID",
                    CustomerID: CustomerID
                },
                async: true,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    if (data.length > 0) {
                        for (i in data) {
                            _optionhtml += "<option value=\"" + data[i].No + "\" >" + data[i].Banci.trim() + "</option>";
                        }

                    }
                    else {
                        dialogMsg("未找到数据", 0);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        // 单台监视grid列表数据
        initdantaijianshitable: function (EquNo, TaiHao, Time) {
            var $gridTable = $('#dantaijianshitable');
            //$("#gridTable").trigger('reloadGrid');
            $gridTable.jqGrid({
                url: "./MFGCusha.ashx",
                postData: {
                    Action: "initdangtaijianshidata",
                    EquNo: EquNo,
                    TaiHao: TaiHao,
                    Time: Time
                },
                datatype: "json",
                // height: $("#dantaijianshitable").height() + 55,
                height: 100,
                autowidth: true,
                colModel: [
                    { label: '台号', name: 'EquNo', index: 'EquNo', width: 80, align: 'left' },
                    { label: '纺纱品种', name: 'Kind', index: 'Kind', width: 100, align: 'left' },
                    { label: '当班产量', name: 'Chanliangm', index: 'Chanliangm', width: 100, align: 'left' },
                    { label: '当前纺纱长度', name: 'dangqianchangdu', index: 'dangqianchangdu', width: 100, align: 'left' },
                    { label: '当前效率', name: 'dangqianxiaolv', index: 'dangqianxiaolv', width: 100, align: 'left' },
                    //{ label: '龙筋位置', name: 'longjinweizhi', index: 'longjinweizhi', width: 100, align: 'left' },
                    { label: '纺纱层数', name: 'cengshu', index: 'cengshu', width: 80, align: 'left' },
                    { label: '锭翼速度', name: 'dingyi', index: 'dingyi', width: 100, align: 'left' },
                    { label: '筒管电机理论转速', name: 'tongguansudu', index: 'tongguansudu', width: 120, align: 'left' },
                    { label: '罗拉电机理论速度', name: 'luolasudu', index: 'luolasudu', width: 120, align: 'left' },
                    { label: '升降电机理论速度', name: 'shengjiangsudu', index: 'shengjiangsudu', width: 120, align: 'left' },
                    { label: '锭翼电机理论速度', name: 'dingyisudu', index: 'dingyisudu', width: 120, align: 'left' },
                    { label: 'A班产量', name: 'ZaobanChanliang', index: 'ZaobanChanliang', width: 100, align: 'left' },
                    { label: 'A班生产时间', name: 'ZaobanShengchanshijian', index: 'ZaobanShengchanshijian', width: 100, align: 'left' },
                    { label: 'A班生产效率', name: 'ZaobanXiaolv', index: 'ZaobanXiaolv', width: 100, align: 'left' },
                    { label: 'B班产量', name: 'ZhongbanChanliang', index: 'ZhongbanChanliang', width: 100, align: 'left' },
                    { label: 'B班生产时间', name: 'ZhongbanShengchanshijian', index: 'ZhongbanShengchanshijian', width: 100, align: 'left' },
                    { label: 'B班生产效率', name: 'ZhongbanXiaolv', index: 'ZhongbanXiaolv', width: 100, align: 'left' },
                    { label: 'C班产量', name: 'WanbanChanliang', index: 'WanbanChanliang', width: 100, align: 'left' },
                    { label: 'C班生产时间', name: 'WanbanShengchanshijian', index: 'WanbanShengchanshijian', width: 100, align: 'left' },
                    { label: 'C班生产效率', name: 'WanbanXiaolv', index: 'WanbanXiaolv', width: 100, align: 'left' },
                    { label: '状态', name: 'zhuangtai', index: 'zhuangtai', width: 100, align: 'left' },
                ],
                viewrecords: true,
                rowNum: 10000,
                rownumbers: true,
                shrinkToFit: false,
                gridview: true,
                onSelectRow: function () {
                    selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                },
                gridComplete: function () {
                    //$.Cushajs.initdantaicushabaojingtable($("#equnolist").find("option:selected").val(), $("#equnolist").find("option:selected").text(), $("#time").text());
                }
            });

        },

        // 单台监视页面中 当前落纱按钮点击 获取当前落纱开始时间  层数
        initcurrentluoshaStartEnd: function (CustomerID, TaiHao, Time) {
            var texttype = $("#parmlist").find('option:selected').text()
            var valuetype = $("#parmlist").find('option:selected').val()
            $.ajax({
                url: "./MFGCusha.ashx",
                data: {
                    Action: "initcurrentluoshaStartEnd",
                    CustomerID: CustomerID,
                    TaiHao: TaiHao,
                    Time: Time,
                    parmValue: valuetype,
                    parmText: texttype
                },
                async: true,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    var chart;
                    var x = [];//X轴
                    var ylilun = [];//Y轴
                    var yshiji = [];//Y轴
                    var xtext = [];//X轴TEXT

                    var chart1;
                    var huanxingtudata = [];
                    console.log(data);
                    if (data.length > 0) {
                        $("#tipStart").animate({ "opacity": 1 }, 500, function () {
                            $("#tipStartValue").text(data[0].tipStartValue);
                            $("#tipEnd").animate({ "opacity": 1 }, 1000, function () {

                                // 折线图

                                $("#tipEndValue").text(data[0].tipEndValue);
                                if (data[0].tipEndValue != "0") {
                                    var quxiandata = data[0].quxian
                                    for (key in quxiandata) {
                                        xtext.push(quxiandata[key].xvalue);
                                        ylilun.push(quxiandata[key].yvaluelilun);
                                        yshiji.push(quxiandata[key].yvalueshiji);
                                    }
                                    // 电机曲线图
                                    $.Cushajs.initdianjiquxian(chart, TaiHao, texttype, xtext, ylilun, yshiji);

                                    //环形图
                                    var huanxingtu = data[0].huanxingtu;

                                    for (key in huanxingtu) {

                                        huanxingtudata.push([huanxingtu[key].name, huanxingtu[key].value])
                                    }
                                    console.log(huanxingtudata)
                                    // 当前落纱停车开车次数环形图: 
                                    $.Cushajs.initdangqiankaitingcehcishupie(chart1, huanxingtudata);

                                }
                                else {
                                    // 电机曲线图
                                    $.Cushajs.initdianjiquxian(chart, TaiHao, texttype, xtext, ylilun, yshiji);
                                    // 当前落纱停车开车次数环形图: 
                                    $.Cushajs.initdangqiankaitingcehcishupie(chart1, huanxingtudata);
                                }
                            })
                        });
                    }
                    else {
                        $("#tipStart").animate({ "opacity": 0 }, 500, function () {
                            $("#tipStartValue").text("");
                            $("#tipEnd").animate({ "opacity": 0 }, 500, function () {
                                $("#tipEndValue").text("");
                            })
                        });
                        dialogMsg("未找到数据", 0);
                        $("#zhexiantu").css("display", "none");
                        $("#tingcehfenxibingtu").css("display", "none");
                        //$.Cushajs.initdianjiquxian(chart, TaiHao, texttype, xtext, ylilun, yshiji);
                        //$.Cushajs.initdangqiankaitingcehcishupie(chart1, huanxingtudata);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        // 电机曲线图
        initdianjiquxian: function (chart, TaiHao, texttype, xtext, ylilun, yshiji) {
            $("#zhexiantu").css("display", "block");
            chart = Highcharts.chart('zhexiantu', {
                title: {
                    useHTML: true,
                    text: TaiHao + '-' + texttype,
                    style: {
                        fontSize: '25px'
                    }
                },
                credits: {
                    enabled: false
                },
                xAxis: [{
                    categories: []
                }],
                yAxis: {
                    title: {
                        text: '转速'
                    }
                },
                tooltip: {
                    crosshairs: true,
                    shared: true
                },
                plotOptions: {
                    series: {
                        label: {
                            connectorAllowed: false
                        }
                    }
                },
                series: [{
                    name: '理论' + texttype,
                }, {
                    name: '实际' + texttype,
                }],
                noData: {
                    // Custom positioning/aligning options
                    position: {
                        //align: 'right',
                        //verticalAlign: 'bottom'
                    },
                    // Custom svg attributes
                    attr: {
                        //'stroke-width': 1,
                        //stroke: '#cccccc'
                    },
                    // Custom css
                    style: {
                        //fontWeight: 'bold',     
                        //fontSize: '15px',
                        //color: '#202030'        
                    }
                }
            });
            chart.xAxis[0].setCategories(xtext);
            chart.series[0].setData(ylilun);
            chart.series[1].setData(yshiji);
            chart.redraw();
        },

        // 当前落纱停车开车次数环形图: 
        initdangqiankaitingcehcishupie: function (chart1, huanxingtudata) {
            $("#tingcehfenxibingtu").css("display", "block");
            chart1 = Highcharts.chart('tingcehfenxibingtu', {
                chart: {
                    type: 'pie',
                    options3d: {
                        enabled: true,
                        alpha: 45
                    }
                },
                title: {
                    useHTML: true,
                    text: '当前落纱停车开车次数',
                    style: {
                        fontSize: '25px'
                    }
                },
                plotOptions: {
                    pie: {
                        innerSize: 100,
                        depth: 45
                    }
                },
                series: [{
                    name: '次数',
                }],
                noData: {
                    // Custom positioning/aligning options
                    position: {
                        //align: 'right',
                        //verticalAlign: 'bottom'
                    },
                    // Custom svg attributes
                    attr: {
                        //'stroke-width': 1,
                        //stroke: '#cccccc'
                    },
                    // Custom css
                    style: {
                        //fontWeight: 'bold',     
                        //fontSize: '15px',
                        //color: '#202030'        
                    }
                }
            });
            chart1.series[0].setData(huanxingtudata);
            chart1.redraw();
        },

        //单台监视  报警列表
        initdantaicushabaojingtable: function (CustomerID, TaiHao, StartTime, EndTime) {

            var $gridTable = $('#gridTabletongji');
            $gridTable.jqGrid({
                url: "../MFG/MFGCusha.ashx",
                postData: {
                    Action: "initdantaicushabaojingtable",
                    CustomerID: CustomerID,
                    TaiHao: TaiHao,
                    StartTime: StartTime,
                    EndTime: EndTime
                },
                datatype: "json",
                height: 300,
                autowidth: true,
                colModel: [
                    { label: '粗纱台号', name: 'EquNo', index: 'EquNo', width: 80, align: 'left' },
                    {
                        label: '报警时间', name: 'AlarmTime', index: 'AlarmTime', width: 400, align: 'left',
                        formatter: function (cellvalue, options, rowObject) {
                            if (rowObject.AlarmEndTime) {
                                return rowObject.AlarmTime + '至' + rowObject.AlarmEndTime
                            } else {
                                return rowObject.AlarmTime
                            }
                        }
                    },
                    { label: '报警信息', name: 'AlarmName', index: 'AlarmName', hidden: true },
                    //{ label: '报警次数', name: 'AlarmCount', index: 'AlarmCount', hidden: true },
                    {
                        label: '报警信息', name: '', index: '', width: 400, align: 'left',
                        formatter: function (cellvalue, options, rowObject) {
                            return '<span class=\"label label-danger\" style="cursor: pointer;" onclick="alarm(\'' + rowObject.EquNo + '\',\'' + rowObject.AlarmName + '\')">' + rowObject.AlarmName + '</span>';
                        }
                    },
                    {
                        label: '故障处理', name: 'AlarmHandle', index: 'AlarmHandle', width: 300, align: 'left'
                    },
                    {
                        label: '备注', name: 'note', index: 'note', width: 200, align: 'left'
                    },
                ],
                viewrecords: true,
                rowNum: 10000,
                rownumbers: true,
                shrinkToFit: false,
                gridview: true,
                onSelectRow: function () {
                    selectedRowIndex = $("#" + this.id).getGridParam('selrow');

                },
                gridComplete: function () {
                    var totalrows = $('#gridTabletongji').jqGrid('getRowData');
                    console.log(totalrows);
                    if (totalrows.length > 0) {
                        $("#guzhangtongjitu").animate({ "opacity": 1 }, 1000, function () {
                            $("body").parent().css("overflow-x", "hidden");
                            $.Cushajs.initGuzhangtogjipie(totalrows);
                        })
                    }
                    else {
                        $("#guzhangtongjitu").animate({ "opacity": 0 }, 1000);
                    }
                }
            });
        },

        // 故障处理按钮点击
        initAlarmHandle: function (EquNo, AlarmName) {

            $.ajax({
                url: "./MFGCusha.ashx",
                data: {
                    Action: "initAlarmHandle",
                    EquNo: EquNo,
                    AlarmName: AlarmName
                },
                async: true,
                type: "post",
                datatype: "json",
                success: function (data) {
                    data = JSON.parse(data);
                    console.log(data);
                    if (JSON.stringify(data) != "{}") {
                        $("#AlarmName").val(data.AlarmName);
                        $("#AlarmHandle").val(data.AlarmHandle);
                        $("#note").val(data.note);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        // 故障类型 饼图
        initGuzhangtogjipie: function (tableData) {

            var AlarmName = [];
            for (var key in tableData) {
                AlarmName.push(tableData[key].AlarmName)
            }
            var obj = new Object();
            var temp = [];
            for (var i = 0; i < AlarmName.length; i++) {

                var dt = AlarmName[i];

                if (obj[dt]) {
                    //存在了 
                    obj[dt]++;
                } else {
                    //不存在 
                    temp.push(dt);
                    obj[dt] = 1;
                }
            }
            var piedata = [];
            // 循环打印出 
            for (var key in obj) {
                var newdata = new Object();
                newdata.name = key;
                newdata.y = obj[key];
                piedata.push(newdata);
            }
            console.log(piedata);
            var chart = Highcharts.chart('guzhangtongjitu', {
                chart: {
                    spacing: [40, 0, 40, 0]
                },
                title: {
                    floating: true,
                    text: '故障类型统计'
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            format: '<b>{point.name}</b>: {point.y} 次',
                            style: {
                                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                            }
                        },
                        point: {
                            events: {
                                mouseOver: function (e) {  // 鼠标滑过时动态更新标题
                                    // 标题更新函数，API 地址：https://api.hcharts.cn/highcharts#Chart.setTitle
                                    console.log(e);
                                    chart.setTitle({
                                        //text: e.target.name + '\t' + point.percentage + ' %'
                                        text: e.target.dataLabel.text.textStr
                                    });
                                },
                                mouseOut: function (e) {  // 鼠标滑过时动态更新标题
                                    // 标题更新函数，API 地址：https://api.hcharts.cn/highcharts#Chart.setTitle
                                    chart.setTitle({
                                        text: '故障类型统计'
                                    });
                                }
                                //, 
                                // click: function(e) { // 同样的可以在点击事件里处理
                                //     chart.setTitle({
                                //         text: e.point.name+ '\t'+ e.point.y + ' %'
                                //     });
                                // }
                            }
                        },
                    }
                },
                series: [{
                    type: 'pie',
                    innerSize: '80%',
                    name: '故障名称',
                    data: piedata
                }]
            }, function (c) { // 图表初始化完毕后的会掉函数
                // 环形图圆心
                var centerY = c.series[0].center[1],
                    titleHeight = parseInt(c.title.styles.fontSize);
                // 动态设置标题位置
                c.setTitle({
                    y: centerY + titleHeight / 2
                });
            });
        },

        // 开停车记录列表数据
        initKaitingcheInfo: function (CustomerID, TaiHao, Type, BanCi, StartTime, EndTime) {
            console.log(BanCi)
            var $gridTable = $('#tb_cushakaitingche');
            $gridTable.jqGrid({
                url: "../CustomerMFG/CustomerMFG.ashx",
                postData: {
                    Action: "initKaitingcheInfo",
                    CustomerID: CustomerID,
                    TaiHao: TaiHao,
                    Type: Type,
                    BanCi: BanCi,
                    StartTime: StartTime,
                    EndTime: EndTime
                },
                datatype: "json",
                height: 100,
                autowidth: true,
                colModel: [
                    { label: '粗纱台号', name: 'TaiHao', index: 'TaiHao', width: 100, align: 'center' },
                    { label: '开停状态', name: 'State', index: 'State', width: 250, align: 'center' },
                    { label: '当前班次', name: 'Banci', index: 'Banci', width: 100, align: 'center' },
                    { label: '次数', name: 'Count', index: 'Count', width: 300, align: 'center' },
                    //{ label: '时间', name: 'Time', index: 'Time', width: 300, align: 'center' },
                    { label: '总用时(min)', name: 'TotalTime', index: 'TotalTime', width: 200, align: 'center' },
                    { label: '平均用时(min)', name: 'AverageTime', index: 'AverageTime', width: 200, align: 'center' },
                    { label: '其他总用时(min)', name: 'AnotherTime', hidden: true },
                ],
                viewrecords: true,
                rowNum: 10000,
                rownumbers: true,
                shrinkToFit: true,
                gridview: true,
                onSelectRow: function () {
                    selectedRowIndex = $("#" + this.id).getGridParam('selrow');

                },
                gridComplete: function () {
                    if ($("#banciselect").find("option:selected").val() == "") {
                        var len = $gridTable.getGridParam("width");
                        $gridTable.jqGrid('hideCol', "Banci");
                        $gridTable.setGridWidth(len);
                    }
                    else {
                        var len = $gridTable.getGridParam("width");
                        $gridTable.jqGrid('showCol', "Banci");
                        $gridTable.setGridWidth(len);
                    }

                    $.Cushajs.initKaitingchedetailInfo(CustomerID, TaiHao, Type, BanCi, StartTime, EndTime);
                    $('#tb_kaitingcehdetail').jqGrid('setGridParam', {
                        postData: {
                            Action: "initKaitingchedetailInfo",
                            CustomerID: CustomerID,
                            TaiHao: TaiHao,
                            Type: Type,
                            BanCi: BanCi,
                            StartTime: StartTime,
                            EndTime: EndTime
                        },
                    }).trigger('reloadGrid');
                }
            });

            $("#btn_SearchKaitingcehg").click(function () {
                var TaiHao = $("#taihaolist").find("option:selected").text();
                var BanCi = $("#banciselect").find("option:selected").val();

                var kaitingcheselect = $("#kaitingcheselect").val();
                var Kaiting_StartTime = $("#Kaiting_StartTime").val();
                var Kaiting_EndTime = $("#Kaiting_EndTime").val();
                if (Kaiting_StartTime == "" || Kaiting_EndTime == "") {
                    dialogMsg("请选择时间", 0);
                }
                else {
                    if (BanCi == "") {
                        $gridTable.jqGrid('setGridParam', {
                            postData: {
                                Action: "initKaitingcheInfo",
                                CustomerID: CustomerID,
                                TaiHao: TaiHao,
                                Type: kaitingcheselect,
                                BanCi: BanCi,
                                StartTime: Kaiting_StartTime,
                                EndTime: Kaiting_EndTime
                            },
                        }).trigger('reloadGrid');
                    }
                    else {
                        $gridTable.jqGrid('setGridParam', {
                            postData: {
                                Action: "initKaitingcheInfo",
                                CustomerID: CustomerID,
                                TaiHao: TaiHao,
                                Type: kaitingcheselect,
                                BanCi: BanCi,
                                StartTime: Kaiting_StartTime,
                                EndTime: Kaiting_EndTime
                            },
                        }).trigger('reloadGrid');
                    }
                }

            });
        },

        // 开停车记录详细信息
        initKaitingchedetailInfo: function (CustomerID, TaiHao, Type, BanCi, StartTime, EndTime) {
            console.log(TaiHao)
            var $gridTable = $('#tb_kaitingcehdetail');
            $gridTable.jqGrid({
                url: "../CustomerMFG/CustomerMFG.ashx",
                postData: {
                    Action: "initKaitingchedetailInfo",
                    CustomerID: CustomerID,
                    TaiHao: TaiHao,
                    Type: Type,
                    BanCi: BanCi,
                    StartTime: StartTime,
                    EndTime: EndTime
                },
                datatype: "json",
                height: 300,
                autowidth: true,
                colModel: [
                    { label: '粗纱台号', name: 'EquNo', index: 'EquNo', width: 100, align: 'center' },
                    { label: '开停状态', name: 'State', index: 'State', width: 250, align: 'center' },
                    { label: '当前班次', name: 'Banci', index: 'Banci', width: 100, align: 'center' },
                    { label: '开始时间', name: 'StartTime', index: 'StartTime', width: 300, align: 'center' },
                    { label: '结束时间', name: 'EndTime', index: 'EndTime', width: 300, align: 'center' },
                    { label: '用时(min)', name: 'InteralTime', index: 'InteralTime', width: 200, align: 'center' },
                    { label: '停车原因', name: 'TingcheReason', index: 'TingcheReason', width: 200, align: 'center' },
                ],
                viewrecords: true,
                rowNum: 10000,
                rownumbers: true,
                shrinkToFit: true,
                gridview: true,
                onSelectRow: function () {
                    selectedRowIndex = $("#" + this.id).getGridParam('selrow');

                },
                gridComplete: function () {
                    if ($("#kaitingcheselect").find("option:selected").val() == "1") {
                        var len = $gridTable.getGridParam("width");
                        $gridTable.jqGrid('hideCol', "TingcheReason");
                        $gridTable.setGridWidth(len);
                    }
                    else {
                        var len = $gridTable.getGridParam("width");
                        $gridTable.jqGrid('showCol', "TingcheReason");
                        $gridTable.setGridWidth(len);
                    }

                    //  选择台号.停车的时候 显示停车曲线图
                    if ($("#taihaolist").find("option:selected").val() != "" && $("#kaitingcheselect").val() == "0") {
                        console.log($("#taihaolist").val())
                        // 当没有选择班次 只有曲线图
                        if ($("#banciselect").find("option:selected").val() == "") {
                            $("body").parent().css("overflow-x", "hidden");
                            var rows = $('#tb_kaitingcehdetail').jqGrid('getRowData'); //获取当前显示的记录
                            if (rows.length > 0) {
                                $("#kaitingcehtongjitu").animate({ "opacity": 1, "width": "100%" }, 1000, "easeInOutBounce", function () {
                                    $("#kaitingcehtongjipie").animate({ "opacity": 0 }, 1000);
                                    $.Cushajs.initkaitingcheline('kaitingcehtongjitu', rows);
                                })
                            }
                        } // 当选择班次 曲线图 饼图
                        else {

                            $("body").parent().css("overflow-x", "hidden");
                            var totalrows = $('#tb_cushakaitingche').jqGrid('getRowData');
                            console.log(totalrows)
                            var rows = $('#tb_kaitingcehdetail').jqGrid('getRowData');
                            if (rows.length > 0) {
                                $("#kaitingcehtongjitu").animate({ "opacity": 1, "width": "65%" }, 1000, "easeInOutBounce", function () {
                                    $.Cushajs.initkaitingcheline('kaitingcehtongjitu', rows)
                                    $("#kaitingcehtongjipie").animate({ "opacity": 1 }, 1000, function () {
                                        $.Cushajs.initkaitingchelinepie('kaitingcehtongjipie', totalrows, rows)
                                    })
                                })
                            }
                        }
                    }
                    else {
                        $("#kaitingcehtongjitu").animate({ "opacity": 0 }, 1000)
                    }
                }
            });

        },

        //实施统计曲线图
        initshishitongjitu: function (CustomerID, TaiHao, parmValue, parmText, tipStartValue, Time) {

            var x = [];//X轴
            var ylilun = [];//Y轴
            var yshiji = [];//Y轴
            var xtext = [];//X轴TEXT
            //var series = [];
            $.ajax({
                type: 'post',
                url: "../MFG/MFGCusha.ashx",
                data: {
                    Action: "initshishitongjitu",
                    CustomerID: CustomerID,
                    TaiHao: TaiHao,
                    valuetype: parmValue,
                    texttype: parmText,
                    tipStartValue: tipStartValue,
                    tipEndValue: tipEndValue,
                    Time: Time
                },
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);
                    console.log(data);

                    //if (valuetype<5) {
                    //    if (data.length > 0) {
                    //        for (key in data) {
                    //            xtext.push(data[key].xvalue);
                    //            ylilun.push(data[key].yvaluelilun);
                    //            yshiji.push(data[key].yvalueshiji);

                    //        }
                    //    }
                    //    console.log(xtext);

                    //    var chart = Highcharts.chart('shishitongjitucontainer', {
                    //        title: {
                    //            useHTML: true,
                    //            text: EquNo + '-' + texttype,
                    //            style: {
                    //                fontSize: '25px'
                    //            }
                    //        },
                    //        credits: {
                    //            enabled: false
                    //        },
                    //        xAxis: [{
                    //            categories: []
                    //        }],
                    //        yAxis: {
                    //            title: {
                    //                text: '转速'
                    //            }
                    //        },
                    //        plotOptions: {
                    //            series: {
                    //                label: {
                    //                    connectorAllowed: false
                    //                }
                    //            }
                    //        },
                    //        series: [{
                    //            name: '理论' + texttype,
                    //        }, {
                    //            name: '实际' + texttype,
                    //        }],
                    //        noData: {
                    //            // Custom positioning/aligning options
                    //            position: {	
                    //                //align: 'right',
                    //                //verticalAlign: 'bottom'
                    //            },
                    //            // Custom svg attributes
                    //            attr: {
                    //                //'stroke-width': 1,
                    //                //stroke: '#cccccc'
                    //            },
                    //            // Custom css
                    //            style: {                    
                    //                //fontWeight: 'bold',     
                    //                //fontSize: '15px',
                    //                //color: '#202030'        
                    //            }
                    //        }
                    //    });
                    //    chart.xAxis[0].setCategories(xtext);
                    //    //chart.series[0].name = "理论" + texttype;
                    //    //chart.series[1].name = "实际" + texttype;
                    //    chart.series[0].setData(ylilun);
                    //    chart.series[1].setData(yshiji);
                    //    //chart.setTitle(title);
                    //}

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }

            })

        },

        //生产目标产量与完成产量列表
        inittb_cushashengchanwancheng: function (CustomerID, time) {

            var $gridTable = $('#tb_cushashengchanwancheng');
            $gridTable.jqGrid({
                url: "../MFG/MFGCusha.ashx",
                postData: {
                    Action: "inittb_cushashengchanwancheng",
                    CustomerID: CustomerID,
                    time: time
                },
                datatype: "json",
                height: 250,
                autowidth: true,
                colModel: [
                    { label: '台号', name: 'TaiHao', index: 'TaiHao', width: 50, align: 'left' },
                    {
                        label: '当前班次', name: 'Banci', index: 'Banci', width: 100, align: 'left',
                        formatter: function (cellvalue, options, rowObject) {
                            if (cellvalue == 1) {
                                return "A班";
                            }
                            else if (cellvalue == 2) {
                                return "B班";
                            }
                            else if (cellvalue == 3) {
                                return "C班";
                            }
                            else return "";
                        }
                    },
                    { label: '纺纱定长', name: 'FangShaDingchang', index: 'FangShaDingchang', width: 100, align: 'left' },
                    { label: '当前纺纱长度', name: 'FangShaChangdu', index: 'FangShaChangdu', width: 100, align: 'left' },
                    { label: '当前效率', name: 'Xiaolv', index: 'Xiaolv', width: 100, align: 'left' },
                    { label: '锭翼电机转速', name: 'DingyiZhuansu', index: 'DingyiZhuansu', width: 100, align: 'left' },
                    { label: '筒管电机转速', name: 'TongguanZhuansu', index: 'TongguanZhuansu', width: 100, align: 'left' },
                    { label: '罗拉电机转速', name: 'LuolaZhuansu', index: 'LuolaZhuansu', width: 100, align: 'left' },
                    { label: '升降电机转速', name: 'ShengjiangZhuansu', index: 'ShengjiangZhuansu', width: 100, align: 'left' },
                    { label: '运行状态', name: 'YunxingState', index: 'YunxingState', width: 100, align: 'left' },
                    { label: '完成产量(M)', name: 'Finish', index: 'Finish', width: 120, align: 'left' },
                    {
                        label: '纺纱品种', name: 'FangShaKind', index: 'FangShaKind', width: 120, align: 'left',
                        //①给当前想合并的单元格设置id
                        cellattr: function (rowId, tv, rawObject, cm, rdata) {
                            return 'id=\'FangShaKind' + rowId + "\'";
                        }
                    },
                    {
                        label: '目标产量(M)', name: 'OutPutTarget', index: 'OutPutTarget', width: 120, align: 'left',
                        //①给当前想合并的单元格设置id
                        cellattr: function (rowId, tv, rawObject, cm, rdata) {
                            return 'id=\'OutPutTarget' + rowId + "\'";
                        }
                    },
                    {
                        label: '已完成产量(M)', name: 'totalFinish', index: 'Finish', width: 150, align: 'left',
                        //①给当前想合并的单元格设置id
                        cellattr: function (rowId, tv, rawObject, cm, rdata) {
                            return 'id=\'totalFinish' + rowId + "\'";
                        }
                    },

                    {
                        label: '状态', name: 'State', index: 'State', width: 100, align: 'center',
                        cellattr: function (rowId, tv, rawObject, cm, rdata) {
                            return 'id=\'State' + rowId + "\'";
                        },
                        formatter: function (cellvalue, options, rowObject) {
                            if (cellvalue == 1) {
                                return '<span  class=\"label label-success\">生产效率正常</span>';
                            } else if (cellvalue == 0) {
                                return '<span  class=\"label label-danger\">生产效率滞后</span>';
                            } else if (cellvalue == 2) {
                                return '<span  class=\"label label-danger\">生产过剩</span>';
                            } else {
                                return '';
                            }

                        }
                    },
                ],
                viewrecords: true,
                rowNum: 10000,
                rownumbers: false,
                shrinkToFit: false,
                gridview: true,
                onSelectRow: function () {
                    //selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                },
                gridComplete: function () {
                    //$.Cushajs.initdantaicushabaojingtable($("#equnolist").find("option:selected").val(), $("#equnolist").find("option:selected").text(), $("#time").text());
                    var gridName = "tb_cushashengchanwancheng";
                    Merger(gridName, 'FangShaKind');
                    Merger(gridName, 'OutPutTarget');
                    Merger(gridName, 'totalFinish');
                    Merger(gridName, 'State');
                    var rows = $('#tb_cushashengchanwancheng').jqGrid('getRowData'); //获取当前显示的记录
                    console.log(rows)
                    var _optionhtml = "";
                    _optionhtml += "<option value=\"" + rows[0].FangShaKind + "\" >" + rows[0].FangShaKind + "</option>"
                    $("#westpanel").animate({ "opacity": 1 }, 500, "easeInOutQuart", function () {
                        //$("#cushakindlist").html(_optionhtml);
                        //$("#cushakindlist1").html(_optionhtml);
                        $("#shengchanwanchengpie").animate({ "opacity": 1, "width": "100%" }, 1000, "easeInOutQuart", function () {
                            $("#centerpanel").animate({ "opacity": 1 }, 1000, function () {
                                $.Cushajs.initShengchanwanchegnWest(rows);
                            })
                        })

                    })
                }
            });
        },

        initShengchanwanchegnWest: function (data) {
            var _html = "";
            console.log(data);
            //var id = "";

            //for (var key = 0; key < data.length; key++) {
            //    if (data[key].FangShaKind.trim() != "" && data[key].FangShaKind!=id) {
            //        id = data[key].FangShaKind;
            //        _html += "<div id=" + data[key].FangShaKind + ">"
            //        _html += "</div>";
            //    }
            //}
            //$("#shengchanwanchengpie").append(_html);

            var id = "";
            var newData = new Array();
            var fangsha = new Object();
            var fangshakind = $("#cushakindlist").val();
            for (var key = 0; key < data.length; key++) {
                if (data[key].FangShaKind.trim() != "" && data[key].FangShaKind != id && data[key].FangShaKind== fangshakind) {
                    id = data[key].FangShaKind;
                    fangsha.FangShaKind = data[key].FangShaKind;
                    fangsha.OutPutTarget = data[key].OutPutTarget;
                    fangsha.totalFinish = data[key].totalFinish;
                    fangsha.detail = [];
                    newData.push(fangsha);
                }
            }

            for (var key = 0; key < newData.length; key++) {
                for (var key1 = 0; key1 < data.length; key1++) {
                    if (newData[key].FangShaKind == data[key1].FangShaKind) {
                        var detailfangsha = new Object();
                        detailfangsha.name = data[key1].TaiHao.trim() + "台号已完成产量";
                        detailfangsha.y = parseInt(data[key1].Finish == "" ? 0 : data[key1].Finish);
                        detailfangsha.sliced = true;
                        detailfangsha.selected = true;
                        newData[key].detail.push(detailfangsha);
                    }

                }
                var weiwancheng = new Object();
                weiwancheng.name = "未完成产量"
                weiwancheng.y = parseInt(newData[key].OutPutTarget - newData[key].totalFinish);
                weiwancheng.color = "#FF0000";
                newData[key].detail.push(weiwancheng);
            }
            console.log(newData)
            $.Cushajs.initShengchanwanchegnPie(newData);
            $.Cushajs.initShengchanwanchegnColumn(newData);
        },

        //生产目标产量与完成产量饼图
        initShengchanwanchegnPie: function (newData) {

            for (var key = 0; key < newData.length; key++) {
                if (newData[key].FangShaKind.trim() != "") {
                    console.log(newData[key].detail);
                    Highcharts.chart(shengchanwanchengpie, {
                        chart: {
                            plotBackgroundColor: null,
                            plotBorderWidth: null,
                            plotShadow: false,
                            type: 'pie'
                        },
                        title: {
                            text: newData[key].FangShaKind + '粗纱生产完成详细情况'
                        },
                        legend: {
                            layout: 'vertical',
                            align: 'right',
                            verticalAlign: 'middle'
                        },
                        plotOptions: {
                            pie: {
                                allowPointSelect: true,
                                cursor: 'pointer',
                                dataLabels: {
                                    enabled: true,
                                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                                    style: {
                                        color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                                    }
                                },
                                showInLegend: true
                            }
                        },
                        series: [{
                            name: '产量值',
                            colorByPoint: true,
                            data: newData[key].detail
                        }]
                    });
                }

            }
        },

        //生产目标产量与完成产量柱状图
        initShengchanwanchegnColumn: function (newData) {
            console.log(newData)
            var x = [];
            var y = [];
            var y1 = [];
            for (var key in newData) {
                x.push("纺纱品种：" + newData[key].FangShaKind);
                y.push(parseInt(newData[key].totalFinish));
                y1.push(parseInt(newData[key].OutPutTarget - newData[key].totalFinish));
            }
            var yvalue = [{
                name: "已完成总产量",
                data: y,
                color: "#ADFF2F"
            }, {
                name: "未完成产量",
                data: y1,
                color: "#FF0000"
            }]
            console.log(x);
            console.log(y);
            var chart = Highcharts.chart('shengchanwanchengcolumn', {
                chart: {
                    type: 'column'
                },
                title: {
                    text: '粗纱总生产完成情况'
                },

                xAxis: {
                    categories: x,
                    crosshair: true
                },
                yAxis: {
                    min: 0,
                    title: {
                        text: '产量值(M)'
                    }
                },
                tooltip: {
                    // head + 每个 point + footer 拼接成完整的 table
                    headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
                    pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                    '<td style="padding:0"><b>{point.y}</b></td></tr>',
                    footerFormat: '</table>',
                    shared: true,
                    useHTML: true
                },
                plotOptions: {
                    column: {
                        borderWidth: 0
                    }
                },
                series: yvalue
            });
        },

        //开停车记录页面 选择台号  选择停车  画曲线图
        initkaitingcheline: function (container, rowData) {
            var chart;
            var xAxis = [];
            var series = [];
            var totaldata = [];
            var tingcheshijian = new Object();
            tingcheshijian.name = "停车时间";

            var tingche = new Object();
            var duansha = new Object();
            var duantiao = new Object();
            var baohu = new Object();
            var jiting = new Object();
            var guzhang = new Object();
            var mansha = new Object();
            var dianche = new Object();
            var menkaiguan = new Object();

            tingche.name = "停车";
            tingche.data = [];
            tingche.show = false;
            duansha.name = "断纱";
            duansha.data = [];
            duansha.show = false;
            duantiao.name = "断条";
            duantiao.data = [];
            duantiao.show = false;
            baohu.name = "保护";
            baohu.data = [];
            baohu.show = false;
            jiting.name = "急停";
            jiting.data = [];
            jiting.show = false;
            guzhang.name = "故障";
            guzhang.data = [];
            guzhang.show = false;
            mansha.name = "满纱";
            mansha.data = [];
            mansha.show = false;
            dianche.name = "点车";
            dianche.data = [];
            dianche.show = false;
            menkaiguan.name = "门开关";
            menkaiguan.data = [];
            menkaiguan.show = false;

            for (var key = 0; key < rowData.length; key++) {
                xAxis.push(key + 1);
                series.push(parseFloat(rowData[key].InteralTime));
                // 停车
                if (rowData[key].TingcheReason.indexOf(tingche.name) != -1) {
                    tingche.data.push(parseFloat(rowData[key].InteralTime));
                    tingche.show = true;
                }
                else {
                    tingche.data.push(null);
                }
                //断纱
                if (rowData[key].TingcheReason.indexOf(duansha.name) != -1) {
                    duansha.data.push(parseFloat(rowData[key].InteralTime));
                    duansha.show = true;
                }
                else {
                    duansha.data.push(null);
                }
                //断条
                if (rowData[key].TingcheReason.indexOf(duantiao.name) != -1) {
                    duantiao.data.push(parseFloat(rowData[key].InteralTime));
                    duantiao.show = true;
                }
                else {
                    duantiao.data.push(null);
                }
                // 保护
                if (rowData[key].TingcheReason.indexOf(baohu.name) != -1) {
                    baohu.data.push(parseFloat(rowData[key].InteralTime));
                    baohu.show = true;
                }
                else {
                    baohu.data.push(null);
                }
                //急停
                if (rowData[key].TingcheReason.indexOf(jiting.name) != -1) {
                    jiting.data.push(parseFloat(rowData[key].InteralTime));
                    jiting.show = true;
                }
                else {
                    jiting.data.push(null);
                }
                //故障
                if (rowData[key].TingcheReason.indexOf(guzhang.name) != -1) {
                    guzhang.data.push(parseFloat(rowData[key].InteralTime));
                    guzhang.show = true;
                }
                else {
                    guzhang.data.push(null);
                }
                //满纱
                if (rowData[key].TingcheReason.indexOf(mansha.name) != -1) {
                    mansha.data.push(parseFloat(rowData[key].InteralTime));
                    mansha.show = true;
                }
                else {
                    mansha.data.push(null);
                }
                //点车
                if (rowData[key].TingcheReason.indexOf(dianche.name) != -1) {
                    dianche.data.push(parseFloat(rowData[key].InteralTime));
                    dianche.show = true;
                }
                else {
                    dianche.data.push(null);
                }
                // 门开关
                if (rowData[key].TingcheReason.indexOf(menkaiguan.name) != -1) {
                    menkaiguan.data.push(parseFloat(rowData[key].InteralTime));
                    menkaiguan.show = true;
                }
                else {
                    menkaiguan.data.push(null);
                }
            }
            tingcheshijian.data = series;

            totaldata.push(tingcheshijian);
            if (tingche.show == true) totaldata.push(tingche);
            if (duansha.show == true) totaldata.push(duansha);
            if (duantiao.show == true) totaldata.push(duantiao);
            if (baohu.show == true) totaldata.push(baohu);
            if (jiting.show == true) totaldata.push(jiting);
            if (guzhang.show == true) totaldata.push(guzhang);
            if (mansha.show == true) totaldata.push(mansha);
            if (dianche.show == true) totaldata.push(dianche);
            if (menkaiguan.show == true) totaldata.push(menkaiguan);

            chart = Highcharts.chart(container, {
                chart: {
                    type: 'line'
                },
                title: {
                    text: '台号:' + rowData[0].EquNo.trim() + '停车信息统计'
                },
                xAxis: {
                    categories: xAxis
                },
                yAxis: {
                    title: {
                        text: '停车时间(min)'
                    }
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle',
                    labelFormatter: function () {
                        /*
                         *  格式化函数可用的变量：this， 可以用 console.log(this) 来查看包含的详细信息
                         *  this 代表当前数据列对象，所以默认的实现是 return this.name 
                         */
                        var count = 0;
                        for (var key = 0; key < this.yData.length; key++) {
                            console.log(this.yData[key])
                            if (this.yData[key] != null) {
                                count++;
                            }
                        }
                        return this.name + ':' + count;
                    }
                },
                tooltip: {
                    crosshairs: true,
                    shared: true
                },
                plotOptions: {
                    spline: {
                        marker: {
                            radius: 4,
                            lineColor: '#666666',
                            lineWidth: 1
                        }
                    }
                },
                series: totaldata
            });
            chart.redraw();
        },

        //开停车记录页面 选择台号  选择停车 选择班次  画曲线图 饼图
        initkaitingchelinepie: function (container, totaldata, rowData) {
            var chart;
            console.log(totaldata)
            var tingche = new Object();
            tingche.name = '停车';
            tingche.y = parseFloat(totaldata[0].TotalTime);
            tingche.sliced = true;
            tingche.selected = true;

            var kaiche = new Object();
            kaiche.name = '开车';
            kaiche.y = parseFloat(totaldata[0].AnotherTime);
            kaiche.color = Highcharts.getOptions().colors[2];

            // 创建渐变色
            //Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function (color) {
            //    return {
            //        radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
            //        stops: [
            //            [0, color],
            //            [1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
            //        ]
            //    };
            //});
            // 构建图表
            chart = Highcharts.chart(container, {
                title: {
                    text: totaldata[0].Banci + '停车占比'
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                            style: {
                                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                            },
                            connectorColor: 'silver'
                        }
                    }
                },
                series: [{
                    type: 'pie',
                    name: '开停车占比',
                    size: '80%',
                    data: [tingche, kaiche]
                }]
            });
            chart.redraw();
        },

        // 尾纱 构造台号select
        initWeiShaTiaHaoByCustomerID: function (CustomerID, type) {

            var _optionhtml = "";

            $.ajax({
                url: "../MFG/MFGCusha.ashx",
                data: {
                    Action: "initWeiShaTaiHaoByCustomerID",
                    CustomerID: CustomerID
                },
                async: true,
                type: "post",
                datatype: "json",
                success: function (data) {
                    Loading(false);
                    data = JSON.parse(data);

                    if (data.length > 0) {
                        _optionhtml += "<option value=''>请选择</option>";
                        for (i in data) {

                            _optionhtml += "<option value=\"" + data[i].EquNo + "\" >" + data[i].TaiHao.trim() + "</option>";
                        }
                        if (type == "1") {
                            $("#weishataihaolist").html(_optionhtml);

                            var TiaHao = $("#weishataihaolist").find("option:selected").text();
                            var BanCi = $("#weishabanciselect").find("option:selected").val();

                            var kaitingcheselect = $("#weishakaitingcheselect").val();
                            var Kaiting_StartTime = $("#weishaKaiting_StartTime").val();
                            var Kaiting_EndTime = $("#weishaKaiting_EndTime").val();

                            $.Cushajs.initweishaKaitingcheInfo(CustomerID, TiaHao, kaitingcheselect, BanCi, Kaiting_StartTime, Kaiting_EndTime);
                        }
                        else if (type == "2") {
                            $("#weisha_guzhangtongjiTaihaolist").html(_optionhtml);
                        }

                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    Loading(false);
                    dialogMsg(errorThrown, -1);
                }
            });
        },

        //尾纱机 基本信息列表 
        initweishajibenxinxi: function (CustomerID, time) {

            var $gridTable = $('#tb_weishajibenxinxi');
            $gridTable.jqGrid({
                url: "../MFG/MFGCusha.ashx",
                postData: {
                    Action: "initweishajibenxinxi",
                    CustomerID: CustomerID,
                    time: time
                },
                datatype: "json",
                height: 250,
                autowidth: true,
                colModel: [
                    { label: '台号', name: 'TaiHao', index: 'TaiHao', width: 100, align: 'left' },
                    {
                        label: '当前班次', name: 'Banci', index: 'Banci', width: 100, align: 'left',
                        formatter: function (cellvalue, options, rowObject) {
                            if (cellvalue == 1) {
                                return "A班";
                            }
                            else if (cellvalue == 2) {
                                return "B班";
                            }
                            else if (cellvalue == 3) {
                                return "C班";
                            }
                            else return "";
                        }
                    },
                    { label: '运行状态', name: 'State', index: 'State', width: 100, align: 'left' },
                    { label: '链条数量', name: 'LianTiaoCount', index: 'LianTiaoCount', width: 150, align: 'left' },
                    { label: '吊锭总数量', name: 'DiaoDingCount', index: 'DiaoDingCount', width: 150, align: 'left' },
                    { label: '清洁目标数量', name: 'TargetCount', index: 'TargetCount', width: 150, align: 'left' },
                    { label: '未清洁数量', name: 'UnFinishCount', index: 'UnFinishCount', width: 150, align: 'left' },
                    { label: '清洁率', name: 'ClearPercent', index: 'ClearPercent', width: 150, align: 'left' },
                    { label: '毛刷时间', name: 'MaoShuaTime', index: 'MaoShuaTime', width: 200, align: 'left' },
                    { label: '风机负压值', name: 'FuYaZhi', index: 'FuYaZhi', width: 150, align: 'left' },
                    { label: '报警压力值', name: 'BaoJingZhi', index: 'BaoJingZhi', width: 150, align: 'left' },
                    { label: '故障压力值', name: 'GuZhangZhi', index: 'GuZhangZhi', width: 150, align: 'left' },
                    { label: '生产状态', name: 'ShengChanState', index: 'ShengChanState', width: 150, align: 'left' },
                ],
                viewrecords: true,
                rowNum: 10000,
                rownumbers: false,
                shrinkToFit: false,
                gridview: true,
                onSelectRow: function () {
                    //selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                },
                gridComplete: function () {
                    var rows = $('#tb_weishajibenxinxi').jqGrid('getRowData'); //获取当前显示的记录
                    console.log(rows)

                    $("#weishawestpanel").animate({ "opacity": 1 }, 500, "easeInOutQuart", function () {
                        $("#weishacenterpanel").animate({ "opacity": 1 }, 1000, "easeInOutQuart", function () {
                            $.Cushajs.initCleanTargetUnFinishPie(rows);
                            $.Cushajs.initCleanTargetUnFinishColumn(rows);
                        })

                    })
                }
            });
        },

        // 尾纱基本信息  清洁目标数量统计饼图
        initCleanTargetUnFinishPie: function (rowData) {

            var newData = [];
            for (var key = 0; key < rowData.length; key++) {
                var detailfangsha = new Object();
                detailfangsha.name = rowData[key].TaiHao.trim() + "台号清洁目标数量";
                detailfangsha.y = parseInt(rowData[key].TargetCount == "" ? 0 : rowData[key].TargetCount);
                detailfangsha.sliced = true;
                detailfangsha.selected = true;
                newData.push(detailfangsha);
            }

            for (var key = 0; key < rowData.length; key++) {
                var detailfangsha = new Object();
                detailfangsha.name = rowData[key].TaiHao.trim() + "台号未清洁数量";
                detailfangsha.y = parseInt(rowData[key].UnFinishCount == "" ? 0 : rowData[key].UnFinishCount);
                newData.push(detailfangsha);
            }

            Highcharts.chart(weishamubiaowanchengpie, {
                chart: {
                    plotBackgroundColor: null,
                    plotBorderWidth: null,
                    plotShadow: false,
                    type: 'pie'
                },
                title: {
                    text: '尾纱清洁目标数量、未清洁数量统计'
                },
                legend: {
                    layout: 'vertical',
                    align: 'right',
                    verticalAlign: 'middle'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                            style: {
                                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                            }
                        },
                        showInLegend: true
                    }
                },
                series: [{
                    name: '数量',
                    colorByPoint: true,
                    data: newData
                }]
            });
        },

        // 尾纱基本信息  清洁目标数量统计柱状图
        initCleanTargetUnFinishColumn: function (rowData) {
            var xtext = [];
            var targetNum = [];
            var unfinishNum = [];
            for (var key = 0; key < rowData.length; key++) {
                xtext.push(rowData[key].TaiHao);
                targetNum.push(parseInt(rowData[key].TargetCount));
                unfinishNum.push(parseInt(rowData[key].UnFinishCount));
            }
            console.log(targetNum);
            console.log(unfinishNum);
            var chart = Highcharts.chart('weishamubiaowanchengcolumn', {
                chart: {
                    type: 'column',
                    options3d: {
                        enabled: true,
                        alpha: 10,
                        beta: 25,
                        depth: 70,
                        viewDistance: 100,      // 视图距离，它对于计算角度影响在柱图和散列图非常重要。此值不能用于3D的饼图
                        frame: {                // Frame框架，3D图包含柱的面板，我们以X ,Y，Z的坐标系来理解，X轴与 Z轴所形成
                            // 的面为bottom，Y轴与Z轴所形成的面为side，X轴与Y轴所形成的面为back，bottom、
                            // side、back的属性一样，其中size为感官理解的厚度，color为面板颜色
                            bottom: {
                                size: 10
                            },
                            side: {
                                size: 1,
                                color: 'transparent'
                            },
                            back: {
                                size: 1,
                                color: 'transparent'
                            }
                        }
                    },
                },
                title: {
                    text: '尾纱清洁目标数量、未清洁数量'
                },
                plotOptions: {
                    column: {
                        depth: 25
                    }
                },
                xAxis: {
                    categories: xtext,
                    crosshair: true
                },
                yAxis: {
                    title: {
                        text: null
                    }
                },
                series: [{
                    name: '清洁目标数量',
                    data: targetNum,
                    color: "#43CD80"
                }, {
                    name: '未清洁数量',
                    data: unfinishNum,
                    color: "#CD0000"
                }]
            });
        },

        //尾纱  报警故障列表
        initdantaiweishabaojingtable: function (CustomerID, TaiHao, StartTime, EndTime) {

            var $gridTable = $('#weisha_gridTabletongji');
            $gridTable.jqGrid({
                url: "../MFG/MFGCusha.ashx",
                postData: {
                    Action: "initdantaiweishabaojingtable",
                    CustomerID: CustomerID,
                    TaiHao: TaiHao,
                    StartTime: StartTime,
                    EndTime: EndTime
                },
                datatype: "json",
                // height: $("#dantaijianshitable").height() + 55,
                height: 300,
                autowidth: true,
                colModel: [
                    { label: '尾纱台号', name: 'TaiHao', index: 'TaiHao', width: 80, align: 'left' },
                    { label: '报警时间', name: 'AlarmTime', index: 'AlarmTime', width: 400, align: 'left' },
                    { label: '报警信息', name: 'AlarmName', index: 'AlarmName', width: 200, align: 'left', },
                ],
                viewrecords: true,
                rowNum: 10000,
                rownumbers: true,
                shrinkToFit: false,
                gridview: true,
                onSelectRow: function () {
                    selectedRowIndex = $("#" + this.id).getGridParam('selrow');

                },
                gridComplete: function () {
                    var totalrows = $('#weisha_gridTabletongji').jqGrid('getRowData');
                    console.log(totalrows);
                    if (totalrows.length > 0) {
                        $("#weisha_guzhangtongjitu").animate({ "opacity": 1 }, 1000, function () {
                            $("body").parent().css("overflow-x", "hidden");
                            $.Cushajs.initweishaGuzhangtogjipie(totalrows);
                        })
                    }
                    else {
                        $("#weisha_guzhangtongjitu").animate({ "opacity": 0 }, 1000);
                    }
                }
            });
        },

        // 尾纱故障类型 饼图
        initweishaGuzhangtogjipie: function (tableData) {

            var AlarmName = [];
            for (var key in tableData) {
                AlarmName.push(tableData[key].AlarmName)
            }
            var obj = new Object();
            var temp = [];
            for (var i = 0; i < AlarmName.length; i++) {

                var dt = AlarmName[i];

                if (obj[dt]) {
                    //存在了 
                    obj[dt]++;
                } else {
                    //不存在 
                    temp.push(dt);
                    obj[dt] = 1;
                }
            }
            var piedata = [];
            // 循环打印出 
            for (var key in obj) {
                var newdata = new Object();
                newdata.name = key;
                newdata.y = obj[key];
                piedata.push(newdata);
            }
            console.log(piedata);
            var chart = Highcharts.chart('weisha_guzhangtongjitu', {
                chart: {
                    spacing: [40, 0, 40, 0]
                },
                title: {
                    floating: true,
                    text: '尾纱故障类型统计'
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                            style: {
                                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                            }
                        },
                        point: {
                            events: {
                                mouseOver: function (e) {  // 鼠标滑过时动态更新标题
                                    // 标题更新函数，API 地址：https://api.hcharts.cn/highcharts#Chart.setTitle
                                    console.log(e);
                                    chart.setTitle({
                                        //text: e.target.name + '\t' + point.percentage + ' %'
                                        text: e.target.dataLabel.text.textStr
                                    });
                                },
                                mouseOut: function (e) {  // 鼠标滑过时动态更新标题
                                    // 标题更新函数，API 地址：https://api.hcharts.cn/highcharts#Chart.setTitle
                                    chart.setTitle({
                                        text: '故障类型统计'
                                    });
                                }
                            }
                        },
                    }
                },
                series: [{
                    type: 'pie',
                    innerSize: '80%',
                    name: '故障名称',
                    data: piedata
                }]
            }, function (c) { // 图表初始化完毕后的会掉函数
                // 环形图圆心
                var centerY = c.series[0].center[1],
                    titleHeight = parseInt(c.title.styles.fontSize);
                // 动态设置标题位置
                c.setTitle({
                    y: centerY + titleHeight / 2
                });
            });
        },

        // 尾纱开停车记录
        initweishaKaitingcheInfo: function (CustomerID, TaiHao, Type, BanCi, StartTime, EndTime) {
            console.log(BanCi)
            var $gridTable = $('#tb_weishakaitingche');
            $gridTable.jqGrid({
                url: "../MFG/MFGCusha.ashx",
                postData: {
                    Action: "initweishaKaitingcheInfo",
                    CustomerID: CustomerID,
                    TaiHao: TaiHao,
                    Type: Type,
                    BanCi: BanCi,
                    StartTime: StartTime,
                    EndTime: EndTime
                },
                datatype: "json",
                height: 100,
                autowidth: true,
                colModel: [
                    { label: '尾纱台号', name: 'TaiHao', index: 'TaiHao', width: 100, align: 'center' },
                    { label: '开停状态', name: 'State', index: 'State', width: 250, align: 'center' },
                    { label: '当前班次', name: 'Banci', index: 'Banci', width: 100, align: 'center' },
                    { label: '次数', name: 'Count', index: 'Count', width: 300, align: 'center' },
                    //{ label: '时间', name: 'Time', index: 'Time', width: 300, align: 'center' },
                    { label: '总用时(min)', name: 'TotalTime', index: 'TotalTime', width: 200, align: 'center' },
                    { label: '平均用时(min)', name: 'AverageTime', index: 'AverageTime', width: 200, align: 'center' },
                    { label: '其他总用时(min)', name: 'AnotherTime', hidden: true },
                ],
                viewrecords: true,
                rowNum: 10000,
                rownumbers: true,
                shrinkToFit: true,
                gridview: true,
                onSelectRow: function () {
                    selectedRowIndex = $("#" + this.id).getGridParam('selrow');

                },
                gridComplete: function () {
                    if ($("#weishabanciselect").find("option:selected").val() == "") {
                        var len = $gridTable.getGridParam("width");
                        $gridTable.jqGrid('hideCol', "Banci");
                        $gridTable.setGridWidth(len);
                    }
                    else {
                        var len = $gridTable.getGridParam("width");
                        $gridTable.jqGrid('showCol', "Banci");
                        $gridTable.setGridWidth(len);
                    }

                    $.Cushajs.initweishaKaitingchedetailInfo(CustomerID, TaiHao, Type, BanCi, StartTime, EndTime);
                    $('#tb_weishakaitingcehdetail').jqGrid('setGridParam', {
                        postData: {
                            Action: "initweishaKaitingchedetailInfo",
                            CustomerID: CustomerID,
                            TaiHao: TaiHao,
                            Type: Type,
                            BanCi: BanCi,
                            StartTime: StartTime,
                            EndTime: EndTime
                        },
                    }).trigger('reloadGrid');
                }
            });

            $("#btn_SearchweishaKaitingche").click(function () {
                var TaiHao = $("#weishataihaolist").find("option:selected").text();
                var BanCi = $("#weishabanciselect").find("option:selected").val();

                var kaitingcheselect = $("#weishakaitingcheselect").val();

                var Kaiting_StartTime = $("#weishaKaiting_StartTime").val();
                var Kaiting_EndTime = $("#weishaKaiting_EndTime").val();

                if (Kaiting_StartTime == "" || Kaiting_EndTime == "") {
                    dialogMsg("请选择时间", 0);
                }
                else {
                    if (BanCi == "") {
                        $gridTable.jqGrid('setGridParam', {
                            postData: {
                                Action: "initweishaKaitingcheInfo",
                                CustomerID: CustomerID,
                                TaiHao: TaiHao,
                                Type: kaitingcheselect,
                                BanCi: BanCi,
                                StartTime: Kaiting_StartTime,
                                EndTime: Kaiting_EndTime
                            },
                        }).trigger('reloadGrid');
                    }
                    else {
                        $gridTable.jqGrid('setGridParam', {
                            postData: {
                                Action: "initweishaKaitingcheInfo",
                                CustomerID: CustomerID,
                                TaiHao: TaiHao,
                                Type: kaitingcheselect,
                                BanCi: BanCi,
                                StartTime: Kaiting_StartTime,
                                EndTime: Kaiting_EndTime
                            },
                        }).trigger('reloadGrid');
                    }
                }

            });
        },

        // 开停车记录详细信息
        initweishaKaitingchedetailInfo: function (CustomerID, TaiHao, Type, BanCi, StartTime, EndTime) {
            console.log(TaiHao)
            var $gridTable = $('#tb_weishakaitingcehdetail');
            $gridTable.jqGrid({
                url: "../MFG/MFGCusha.ashx",
                postData: {
                    Action: "initweishaKaitingchedetailInfo",
                    CustomerID: CustomerID,
                    TaiHao: TaiHao,
                    Type: Type,
                    BanCi: BanCi,
                    StartTime: StartTime,
                    EndTime: EndTime
                },
                datatype: "json",
                height: 300,
                autowidth: true,
                colModel: [
                    { label: '粗纱台号', name: 'EquNo', index: 'EquNo', width: 100, align: 'center' },
                    { label: '开停状态', name: 'State', index: 'State', width: 250, align: 'center' },
                    { label: '当前班次', name: 'Banci', index: 'Banci', width: 100, align: 'center' },
                    { label: '开始时间', name: 'StartTime', index: 'StartTime', width: 300, align: 'center' },
                    { label: '结束时间', name: 'EndTime', index: 'EndTime', width: 300, align: 'center' },
                    { label: '用时(min)', name: 'InteralTime', index: 'InteralTime', width: 200, align: 'center' },
                    { label: '停车原因', name: 'TingcheReason', index: 'TingcheReason', width: 200, align: 'center' },
                ],
                viewrecords: true,
                rowNum: 10000,
                rownumbers: true,
                shrinkToFit: true,
                gridview: true,
                onSelectRow: function () {
                    selectedRowIndex = $("#" + this.id).getGridParam('selrow');

                },
                gridComplete: function () {
                    if ($("#weishakaitingcheselect").find("option:selected").val() == "1") {
                        var len = $gridTable.getGridParam("width");
                        $gridTable.jqGrid('hideCol', "TingcheReason");
                        $gridTable.setGridWidth(len);
                    }
                    else {
                        var len = $gridTable.getGridParam("width");
                        $gridTable.jqGrid('showCol', "TingcheReason");
                        $gridTable.setGridWidth(len);
                    }

                    //  选择台号.停车的时候 显示停车曲线图
                    if ($("#weishataihaolist").find("option:selected").val() != "" && $("#weishakaitingcheselect").val() == "0") {

                        // 当没有选择班次 只有曲线图
                        if ($("#weishabanciselect").find("option:selected").val() == "") {
                            $("body").parent().css("overflow-x", "hidden");
                            var rows = $('#tb_weishakaitingcehdetail').jqGrid('getRowData'); //获取当前显示的记录
                            if (rows.length > 0) {
                                $("#weisha_kaitingcehtongjitu").animate({ "opacity": 1, "width": "100%" }, 1000, "easeInOutBounce", function () {
                                    $("#weisha_kaitingcehtongjipie").animate({ "opacity": 0 }, 1000);
                                    $.Cushajs.initweishakaitingcheline('weisha_kaitingcehtongjitu', rows);
                                })
                            }
                        } // 当选择班次 曲线图 饼图
                        else {

                            $("body").parent().css("overflow-x", "hidden");
                            var totalrows = $('#tb_weishakaitingche').jqGrid('getRowData');
                            console.log(totalrows)
                            var rows = $('#tb_weishakaitingcehdetail').jqGrid('getRowData');
                            if (rows.length > 0) {
                                $("#weisha_kaitingcehtongjitu").animate({ "opacity": 1, "width": "65%" }, 1000, "easeInOutBounce", function () {
                                    $.Cushajs.initweishakaitingcheline('weisha_kaitingcehtongjitu', rows)
                                    $("#weisha_kaitingcehtongjipie").animate({ "opacity": 1 }, 1000, function () {
                                        $.Cushajs.initweishakaitingchelinepie('weisha_kaitingcehtongjipie', totalrows, rows)
                                    })

                                })
                            }
                        }
                    }
                    else {
                        $("#weisha_kaitingcehtongjitu").animate({ "opacity": 0 }, 1000)
                    }
                }
            });

        },

        //尾纱开停车记录页面 选择台号  选择停车  画曲线图
        initweishakaitingcheline: function (container, rowData) {
            var chart;
            var xAxis = [];
            var series = [];
            var totaldata = [];
            var tingcheshijian = new Object();
            tingcheshijian.name = "停车次数";

            var dandingban = new Object();
            var guore = new Object();
            var fuya = new Object();
            var baohu = new Object();
            var zhanwei = new Object();
            var dashaxinhao = new Object();
            var guaguan = new Object();
       
            dandingban.name = "单锭板报警";
            dandingban.data = [];
            dandingban.show = false;
            guore.name = "风机过热保护";
            guore.data = [];
            guore.show = false;
            fuya.name = "风机负压报警";
            fuya.data = [];
            fuya.show = false;
            baohu.name = "保护光电";
            baohu.data = [];
            baohu.show = false;
            zhanwei.name = "有占位信号";
            zhanwei.data = [];
            zhanwei.show = false;
            dashaxinhao.name = "有大纱信号";
            dashaxinhao.data = [];
            dashaxinhao.show = false;
            guaguan.name = "挂管报警";
            guaguan.data = [];
            guaguan.show = false;
        
            for (var key = 0; key < rowData.length; key++) {
               xAxis.push(key + 1);
               series.push(parseFloat(rowData[key].InteralTime));
                // 单锭板报警
               if (rowData[key].TingcheReason.indexOf(dandingban.name) != -1) {
                   dandingban.data.push(parseFloat(rowData[key].InteralTime));
                   dandingban.show = true;
               }
               else {
                   dandingban.data.push(null);
               }
                //风机过热保护
               if (rowData[key].TingcheReason.indexOf(guore.name) != -1) {
                   guore.data.push(parseFloat(rowData[key].InteralTime));
                   guore.show = true;
               }
               else {
                   guore.data.push(null);
               }
                //风机负压报警
               if (rowData[key].TingcheReason.indexOf(fuya.name) != -1) {
                   fuya.data.push(parseFloat(rowData[key].InteralTime));
                   fuya.show = true;
               }
               else {
                   fuya.data.push(null);
               }
                // 保护光电
               if (rowData[key].TingcheReason.indexOf(baohu.name) != -1) {
                   baohu.data.push(parseFloat(rowData[key].InteralTime));
                   baohu.show = true;
               }
               else {
                   baohu.data.push(null);
               }
                //有占位信号
               if (rowData[key].TingcheReason.indexOf(zhanwei.name) != -1) {
                   zhanwei.data.push(parseFloat(rowData[key].InteralTime));
                   zhanwei.show = true;
               }
               else {
                   zhanwei.data.push(null);
               }
                //有大纱信号
               if (rowData[key].TingcheReason.indexOf(dashaxinhao.name) != -1) {
                   dashaxinhao.data.push(parseFloat(rowData[key].InteralTime));
                   dashaxinhao.show = true;
               }
               else {
                   dashaxinhao.data.push(null);
               }
                //挂管报警
               if (rowData[key].TingcheReason.indexOf(guaguan.name) != -1) {
                   guaguan.data.push(parseFloat(rowData[key].InteralTime));
                   guaguan.show = true;
               }
               else {
                   guaguan.data.push(null);
               }
              }
              tingcheshijian.data = series;

              totaldata.push(tingcheshijian);
              if (dandingban.show == true) totaldata.push(dandingban);
              if (guore.show == true) totaldata.push(guore);
              if (fuya.show == true) totaldata.push(fuya);
              if (baohu.show == true) totaldata.push(baohu);
              if (baohu.show == true) totaldata.push(baohu);
              if (zhanwei.show == true) totaldata.push(zhanwei);
              if (dashaxinhao.show == true) totaldata.push(dashaxinhao);
              if (guaguan.show == true) totaldata.push(guaguan);
              
              chart = Highcharts.chart(container, {
                 chart: {
                   type: 'line'
              },
              title: {
                text: '台号:' + rowData[0].EquNo.trim() + '停车信息统计'
              },
              xAxis: {
                  categories: xAxis
               },
              yAxis: {
                 title: {
                    text: '停车时间(min)'
                }
               },
              legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                labelFormatter: function () {
                    /*
                     *  格式化函数可用的变量：this， 可以用 console.log(this) 来查看包含的详细信息
                     *  this 代表当前数据列对象，所以默认的实现是 return this.name 
                     */
                    var count = 0;
                    for (var key = 0; key < this.yData.length; key++) {
                        console.log(this.yData[key])
                        if (this.yData[key] != null) {
                            count++;
                        }
                    }
                    return this.name + ':' + count;
                }
              },
              tooltip: {
                crosshairs: true,
                shared: true
              },
              plotOptions: {
                spline: {
                    marker: {
                        radius: 4,
                        lineColor: '#666666',
                        lineWidth: 1
                    }
                }
             },
             series: totaldata
           });
           chart.redraw();
        },

        //开停车记录页面 选择台号  选择停车 选择班次  画曲线图 饼图
        initweishakaitingchelinepie: function (container, totaldata, rowData) {
            var chart;
            console.log(totaldata)
            var tingche = new Object();
            tingche.name = '停车';
            tingche.y = parseFloat(totaldata[0].TotalTime);
            tingche.sliced = true;
            tingche.selected = true;

            var kaiche = new Object();
            kaiche.name = '开车';
            kaiche.y = parseFloat(totaldata[0].AnotherTime);
            kaiche.color = Highcharts.getOptions().colors[2];

            // 创建渐变色
            //Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function (color) {
            //    return {
            //        radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
            //        stops: [
            //            [0, color],
            //            [1, Highcharts.Color(color).brighten(-0.3).get('rgb')] // darken
            //        ]
            //    };
            //});
            // 构建图表
            chart = Highcharts.chart(container, {
                title: {
                    text: totaldata[0].Banci + '停车占比'
                },
                tooltip: {
                    pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                },
                plotOptions: {
                    pie: {
                        allowPointSelect: true,
                        cursor: 'pointer',
                        dataLabels: {
                            enabled: true,
                            format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                            style: {
                                color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
                            },
                            connectorColor: 'silver'
                        }
                    }
                },
                series: [{
                    type: 'pie',
                    name: '开停车占比',
                    size: '80%',
                    data: [tingche, kaiche]
                }]
            });
            chart.redraw();
        }
    };


    $(function () {

    });

    function Merger(gridName, CellName) {
        //得到显示到界面的id集合
        var mya = $("#" + gridName + "").getDataIDs();
        //当前显示多少条
        var length = mya.length;
        for (var i = 0; i < length; i++) {
            //从上到下获取一条信息
            var before = $("#" + gridName + "").jqGrid('getRowData', mya[i]);
            //定义合并行数
            var rowSpanTaxCount = 1;
            for (j = i + 1; j <= length; j++) {
                //和上边的信息对比 如果值一样就合并行数+1 然后设置rowspan 让当前单元格隐藏
                var end = $("#" + gridName + "").jqGrid('getRowData', mya[j]);
                if (before[CellName] == end[CellName]) {
                    rowSpanTaxCount++;
                    $("#" + gridName + "").setCell(mya[j], CellName, '', { display: 'none' });
                } else {
                    rowSpanTaxCount = 1;
                    break;
                }
                $("#" + CellName + "" + mya[i] + "").attr("rowspan", rowSpanTaxCount);
            }
        }
    }


})(jQuery);